import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class TestHH {
    public static void main(String[] args) {
        int a[] = new int[6];
        int b[] = new int[3];
        int temp = 0;
        int all;
        Scanner sc = new Scanner(System.in);
        all = sc.nextInt();
        List<int[]> list = new ArrayList<>();
        List<int[]> list1 = new ArrayList<>();
        for (int i = 0; i<all; i++){
            a[0] = sc.nextInt();
            a[1] = sc.nextInt();
            a[2] = sc.nextInt();
            a[3] = sc.nextInt();
            a[4] = sc.nextInt();
            a[5] = sc.nextInt();
            list.add(a);
        }
        for (int i = 0; i<all; i++) {
            a = list.get(i);
            b[2] = a[2] + a[5];
            if (b[2] > 59) {
                temp = 1;
                b[2] = b[2] - 60;
            }
            b[1] = a[1] + a[4];
            if (temp == 1) {
                b[1] = b[1] + 1;
            }
            temp = 0;
            if (b[1] > 59) {
                temp = 1;
                b[1] = b[1] - 60;
            }
            b[0] = a[0] + a[3];
            if (temp == 1) {
                b[0] = b[0] + 1;
            }
            list1.add(b);
        }
        System.out.println(list1);
    }
}
